<template>
	<view class="page">
		<u-sticky>
			<view class="tab-list">
				<view class="tab-item" v-for="(item, index) in tabs" :key="index" @click="tabChange(item, index)">
					<view class="value" :class="current == index ? 'active' : ''">{{ item.name }}</view>
					<view class="line" v-if="current == index"></view>
				</view>
			</view>
		</u-sticky>
		<view class="person-list">
			<view class="person-item" v-for="(item, index) in orderList" :key="index">
				<view class="top-info">
					<view class="username">{{ item.serviceName }}</view>
					<view class="create-time">{{ item.createTime }}</view>
				</view>
				<view class="user-phone-num" v-if="item.patientName && item.patientPhone">{{ item.patientName }}
					({{ item.patientPhone }})</view>
				<view class="user-phone-num" v-else>就诊医院：{{ item.hospitalName }}</view>
				<view class="top-info" style="padding-top: 8rpx;">
					<view class="phone-num">来源：{{ item.sourceUserName }}</view>
					<view class="money">
						佣金：
						<text>￥{{ item.balance }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPromotionOrderList
	} from '@/apis/request.js';

	export default {
		data() {
			return {
				current: 0,
				tabs: [{
						name: '直推'
					},
					{
						name: '间推'
					}
				],
				orderList: [],
				params: {
					pageNo: 1,
					pageSize: 10,
					type: 1
				}
			};
		},
		methods: {
			tabChange(item, index) {
				this.current = index;
				this.params.type = index + 1;
				this.getList();
			},
			getList() {
				getPromotionOrderList(this.params).then(res => {
					if (this.params.pageNo == 1) {
						this.orderList = res.records;
					} else {
						if (this.orderList.length < res.total) {
							this.orderList = this.orderList.concat(res.records);
						} else {
							this.orderList = thid.orderList;
						}
					}
				});
			}
		},
		onLoad() {
			this.getList();
		},
		onPullDownRefresh() {
			this.params.pageNo = 1;
			this.orderList = [];
			this.getList();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.params.pageNo++;
			this.getList();
		}
	};
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f2f2f2ff;
		height: 100%;
		min-height: 100vh;

		.tab-list {
			background-color: #fff;
			border-bottom: 2rpx solid #f1f1f1;
			width: 750rpx;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.tab-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 28rpx;
				color: #999999;

				.value {
					padding: 30rpx 0 24rpx 0;
				}

				.line {
					width: 28rpx;
					height: 6rpx;
					border-radius: 3rpx;
					background: #32C59A;
				}
			}

			.active {
				font-size: 30rpx;
				color: #020202;
			}
		}

		.person-list {
			view:first-child {
				margin-top: 0;
			}

			.person-item {
				margin-top: 20rpx;
				padding: 30rpx;
				background-color: #fff;

				.user-phone-num {
					color: #666666;
					font-size: 22rpx;
					padding: 18rpx 0;
					border-bottom: 2rpx solid #efefef;
				}

				.top-info {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.username {
						font-size: 30rpx;
					}

					.create-time {
						font-size: 22rpx;
						color: #999999;
					}

					.money {
						font-size: 26rpx;
						color: #666666;

						text {
							color: #020202;
						}
					}
				}

				.phone-num {
					margin-top: 14rpx;
					font-size: 22rpx;
					color: #999999;
				}
			}
		}
	}
</style>